package com.tesis_2.UI;

import org.json.JSONException;

import com.example.t2_clientback.R;
import com.example.t2_clientback.R.layout;
import com.example.t2_clientback.R.menu;
import com.tesis_2.BL.BLLocales;
import com.tesis_2.BL.BLPlatos;
import com.tesis_2.MO.MOLocal;
import com.tesis_2.MO.MOPlato;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;

public class UIRegistrarPlato extends Activity {
	
	private int nRest;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_uiregistrar_plato);
		Bundle b = getIntent().getExtras();
		nRest = b.getInt("RestId");
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_uiregistrar_plato, menu);
		return true;
	}
	
	public boolean onOptionsItemSelected(MenuItem item) {
	    
		Intent intent; 
		
		switch (item.getItemId()) 
	    {
	        case R.id.optGuardar_registrar_plato:
	        			
				savePlato();
			
	        break;
	        
	        default: 
	        	
	        break;
	    }
	    return false;
	}
	
	public void savePlato()
	{
		String nombre = ((EditText) findViewById(R.id.txtNombre_registrar_plato)).getText().toString();
		String descr = ((EditText) findViewById(R.id.txtDescr_registrar_plato)).getText().toString();
		String cost = ((EditText) findViewById(R.id.txtCosto_registrar_plato)).getText().toString();
		
		MOPlato obPLato = new MOPlato();
		
		obPLato.setName(nombre.replace(" ", "%20"));
		obPLato.setDescr(descr.replace(" ", "%20"));
		obPLato.setCost(Float.parseFloat(cost));
		obPLato.setRestaurant_id(nRest);
		
	
		try {
			obPLato = BLPlatos.createPlato(obPLato);
			finish();
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
